/* Pontificia Universidad Javeriana - Facultad de Ingenier�a   */

package BESA.Agent.Event;

/* Proyecto Arquitectura SMA - Plataforma BESA - 2002          */

import BESA.Agent.GuardBESA;
import BESA.Exception.ExceptionBESA;
import BESA.SystemLevel.AdmBESA;
import java.io.Serializable;

public class EventBESA extends ACLBESA  implements Serializable {

    /**
	 * 
	 */
	private static final long serialVersionUID = 2114119228878598644L;
	/**
	 * @uml.property  name="type"
	 */
    private String type;
    /**
	 * @uml.property  name="source"
	 */
    private byte source;
    /**
	 * @uml.property  name="priority"
	 */
    private byte priority;
    /**
	 * @uml.property  name="senderAgId"
	 */
    private String senderAgId;
    /**
	 * @uml.property  name="guard"
	 * @uml.associationEnd  
	 */
    private transient GuardBESA guard;
    /**
	 * @uml.property  name="stamp"
	 */
    private int stamp;

    // Constantes para definir prioridad de un evento
    public final static byte EV_PRIORITY_MAX = (byte)127;
    public final static byte EV_PRIORITY_NORMAL = (byte)0;
    public final static byte EV_SOURCE_BESA =    (byte)-127;
    public final static byte EV_PRIORITY_MIN = (byte) - 127;
    // Constantes para definir fuente que genera un evento
    public final static byte EV_SOURCE_INTUSER = (byte)64;
    public final static byte EV_SOURCE_EXTUSER = (byte)127;

    public EventBESA(String evType, DataBESA data, byte priority) {
        super();
        this.stamp = EventStamp.nextStamp();
        this.source = EV_SOURCE_INTUSER;
        this.type = evType;
        setData(data);
        this.priority = priority;
        this.guard = null;
        this.senderAgId = null;
    }

    public EventBESA(String evType, DataBESA data) {
        super();
        this.stamp = EventStamp.nextStamp();
        this.source = EV_SOURCE_INTUSER;
        this.type = evType;
        setData(data);
        this.priority = EV_PRIORITY_NORMAL;
        this.guard = null;
        this.senderAgId = null;
    }

    public EventBESA(String evType, double passwd) throws Exception{
	    super();
		if (AdmBESA.getInstance().verifyPasswd(passwd)){
	        this.stamp = EventStamp.nextStamp();
	        this.source = EV_SOURCE_BESA;
	        this.type = evType;
	        this.priority = EV_PRIORITY_MAX;
	        this.guard = null;
	        this.senderAgId = null;
        }
        else{
			throw new ExceptionBESA("[EventBESA::EventBESA]:Invalid Password");
        }
    }

    public EventBESA(String evType, String senderAgId, DataBESA data, byte priority) {
        super();
        this.stamp = EventStamp.nextStamp();
        this.source = EV_SOURCE_INTUSER;
        this.type = evType;
        setData(data);
        this.priority = priority;
        this.guard = null;
        this.senderAgId = senderAgId;
    }

    public EventBESA(String evType, String senderAgId, DataBESA data) {
        super();
        this.stamp = EventStamp.nextStamp();
        this.source = EV_SOURCE_INTUSER;
        this.type = evType;
        setData(data);
        this.priority = EV_PRIORITY_NORMAL;
        this.guard = null;
        this.senderAgId = senderAgId;
    }

    /**
	 * @return  Returns the type.
	 * @uml.property  name="type"
	 */
    public String getType() {
        return this.type;
    }

    /**
	 * @return  Returns the source.
	 * @uml.property  name="source"
	 */
    public byte getSource() {
        return source;
    }

    /**
	 * @param source  The source to set.
	 * @uml.property  name="source"
	 */
    public void setSource(byte source) {
        this.source = source;
    }

    /**
	 * @return  Returns the priority.
	 * @uml.property  name="priority"
	 */
    public byte getPriority() {
        return priority;
    }

    /**
	 * @param priority  The priority to set.
	 * @uml.property  name="priority"
	 */
    public void setPriority(byte priority) {
        this.priority = priority;
    }

    /**
	 * @return  Returns the senderAgId.
	 * @uml.property  name="senderAgId"
	 */
    public String getSenderAgId(){ return senderAgId; }

    /**
	 * @param senderAgId  The senderAgId to set.
	 * @uml.property  name="senderAgId"
	 */
    public void setSenderAgId(String senderAgId){ this.senderAgId = senderAgId; }

    /**
	 * @return  Returns the guard.
	 * @uml.property  name="guard"
	 */
    public GuardBESA getGuard() {
        return guard;
    }

    /**
	 * @param guard  The guard to set.
	 * @uml.property  name="guard"
	 */
    public void setGuard(GuardBESA guard) {
        this.guard = guard;
    }

    /**
	 * @return  Returns the stamp.
	 * @uml.property  name="stamp"
	 */
    public int getStamp(){
        return stamp;
    }

    public String toString() {
        return Integer.toString(this.getStamp());
    }
}
